package com.maishi.programmer.jainzhioffer;

/**
 * Created by brossdong on 2018/5/13.
 * 斐波那契数列
 */
public class TestProblem10 {

    /**
     * 大家都知道斐波那契数列，现在要求输入一个整数n，请你输出斐波那契数列的第n项。
     * n<=39
     */
    public int Fibonacci(int n) {
        int result = 0;
        int begin = 0;
        int start = 0;
        if (n == 0) return 0;
        if (n == 1) return 1;
        for (int i = 2;i <=n;i++) {
            result = begin + start;
            begin = start;
            start = result;
        }
        return result;
    }
}
